package cn.marinda.resturants.mapper;

import cn.marinda.resturants.entity.Orders;
import cn.marinda.resturants.global.Pages;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.util.List;

/** 订单mapper
 * @date 2021/11/16
 * @author Marinda
 */
public interface OrdersMapper extends BaseMapper<Orders> {

    /** 搜索指定台号的订单信息
     *
     * @param id 台号id
     * @return 订单信息
     */
    @Select("select * from r_orders where id = #{id}")
    Orders selectId(String id);

    /** 通过订单uid找到用户id
     *
     * @param uid 用户uid
     * @return 订单信息
     */
    @Select("select user_uid from r_orders where uid = #{uid}")
    String selectOrderUid(String uid);

    /** 查询订单开始时间和订单结束时间的区间订单列
     *
     * @param startDate 开始时间
     * @param endDate 结束时间
     * @return 列表订单
     */

    @Select("select * from r_orders where start_date in(select start_date from r_orders where start_date between #{startDate} and #{endDate}) and end_date in(select end_date from r_orders where end_date between #{start_date} and #{end_date}) ")
    List<Orders> selectStartDateAndEndDateInterval(String startDate , String endDate);


    /** 查询这个用户的所有订单项
     *
     * @param user_uid userUid
     * @return 订单列
     */
    @Select("select * from r_orders where user_uid = #{user_uid}")

    List<Orders> selectUserOrderList(String user_uid);

    /** 查询指定uuid的订单的总消费金额
     *
     * @param uid uid
     * @return 总消费金额
     */
    @Select("select pay_number from r_orders where uid = #{uid}")
    BigDecimal selectOrderNumber(String uid);

    /** 订单分页
     *
     * @param pages 分页
     * @return 订单分页结果
     */
    @Select("select * from r_orders ")
    IPage<Orders> selectOrderPage(Pages<?> pages);
}


